var self = this
importScripts('tsdemux.js')
Module.onRuntimeInitialized = function() { //此时才能获得完整Module对象
	console.log(Module);
	self.test.onLoadFlag = true;
	self.test.initWorker();
}
function Test() {
}
Test.prototype.decoder = function (data) {//u8Array
    let sample = new Uint8Array(data);
	let count = sample.length/188;
	for(let i=0;i<count;i++){
		for(let j=0;j<188;j++){
			Module._setPacket(j,sample[j]);
		}
		Module._demuxer();
	}
}
Test.prototype.initWorker = function () {
	Module.onDemux = function(array){
			//let postBuffer = new Uint8Array(array.length);
			//for(let i=0;i<array.length;i++){
			//	postBuffer[i] = array[i];
			//}
			self.postMessage(array.data.buffer,[array.data.buffer]);
		}
}
self.test = new Test();
self.onmessage = function (evt) {
    //console.log(`子线程Reveived msg: ${evt.data}`)
	if(self.test.onLoadFlag){
		self.test.decoder(evt.data);
	} 
}
